package com.spic.business.violation.supervision.speed.domain;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.spic.common.core.annotation.Excel;
import lombok.Builder;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Description 采集车辆信息
 * @Author AnQi
 * @Date 2021/10/13
 */
@Data
@Builder
public class VehicleSpeedRecordDTO {
    /** 行驶区域 */
    private String illegalArea;

    /** 违章时间 */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm")
    @Excel(name = "违章时间", width = 30, dateFormat = "yyyy-MM-dd HH:mm")
    private Date illegalTime;

    /**
     * 车辆类型
     */
    private String vehicleType;

    /** 关联车辆 */
    @Excel(name = "关联车辆")
    private String vehicleNumber;

    /** 行驶速度 */
    private Double runningSpeed;

    /** 关联部门 */
    @Excel(name = "关联部门")
    private String associatedDept;

    static String[] areas = new String[]{"1","2"};
    static Double[] speeds = new Double[]{10D, 20D, 30D, 40D, 50D, 50D};
    static String[] vehicleNumbers = new String[]{"蒙G001","蒙G002","蒙G003"};
    static String[] vehicleTypes = new String[]{"1","2"};
    static int getRandomIndex(int maxIndex){
        return 0 + (int)(Math.random() * (maxIndex-0));
    }

    public ViolationsSpeedRecord toRecord(){
        return ViolationsSpeedRecord.builder()
                .illegalArea(this.getIllegalArea())
                .runningSpeed(this.getRunningSpeed())
                .illegalTime(this.illegalTime)
                .illegalType(this.vehicleType)
                .illegalSources("1")
                .vehicleNumber(this.vehicleNumber)
                .build();
    }

    static VehicleSpeedRecordDTO generateOne(){
     return    VehicleSpeedRecordDTO.builder()
                .illegalArea(areas[getRandomIndex(areas.length)])
                .runningSpeed(speeds[getRandomIndex(speeds.length)])
                .vehicleNumber(vehicleNumbers[getRandomIndex(vehicleNumbers.length)])
                .illegalTime(new Date(System.currentTimeMillis()))
                .vehicleType(vehicleTypes[getRandomIndex(vehicleTypes.length)])
                 .build();
    }

    public static List<VehicleSpeedRecordDTO> generate(){
        int cnt = 2;
        List<VehicleSpeedRecordDTO> list = new ArrayList<>(cnt);
        for (int i = 0; i < cnt; i++) {
            list.add(generateOne());
        }
        return list;
    }

    public static void main(String[] args) {
        System.out.println(generate());
    }

}
